#include <cstdio>
#include <cstring>
#define max_digits 100

class big_integer{
public:
    int digit[max_digits];
    int size;
    void init(){
        for (int i = 0; i < max_digits; i++)
            digit[i] = 0;
        size = 0;
    }
    void set(int x){
        init();
        do {
            digit[size++] = x % 10000;
            x /= 10000;
        } while (x != 0);
    }
    void output(){
        for (int i = size - 1; i >= 0; i--){
            if (i != size - 1)
                printf("%04d", digit[i]);
            else
                printf("%d", digit[i]);
        }
        printf("\n");
    }
    big_integer operator * (int x) const{
        big_integer return_num;
        return_num.init();
        int carry = 0;
        for (int i = 0; i < size; i++){
            int temp_num = x * digit[i] + carry;
            carry = temp_num / 10000;
            temp_num %= 10000;
            return_num.digit[return_num.size++] = temp_num;
        }
        if (carry != 0)
            return_num.digit[return_num.size++] = carry;
        return return_num;
    }

    big_integer operator + (const big_integer &big_num) const{
        big_integer return_num;
        return_num.init();
        int carry = 0;
        for (int i = 0; i < big_num.size || i < size; i++){
            int temp_num = big_num.digit[i] + digit[i] + carry;
            carry = temp_num/10000;
            temp_num %= 10000;
            return_num.digit[return_num.size++] = temp_num;
        }
        if (carry != 0)
            return_num.digit[return_num.size++] = carry;
        return return_num;
    }

    big_integer operator / (int x) const{
        big_integer return_num;
        return_num.init();
        int remainder = 0;
        for (int i = size - 1; i >= 0; i--){
            int temp_num = (remainder * 10000 + digit[i]) / x;
            int temp_r = (remainder * 10000 + digit[i]) % x;
            return_num.digit[i] = temp_num;
            remainder = temp_r;
        }
        return_num.size = 0;
        for (int i = 0; i < max_digits; i++){
            if (digit[i] != 0)
                return_num.size = i;
        }
        return_num.size++;
        return return_num;
    }

    int operator % (int x) const{
        int remainder = 0;
        for (int i = size - 1; i >= 0; i--){
            int temp_num = (remainder * 10000 + digit[i]) / x;
            int temp_r = (remainder * 10000 + digit[i]) % x;
            remainder = temp_r;
        }
        return remainder;
    }
} num_a, num_b, num_c;

char input_num[10000];
char result[10000];

int main(int argc, char const *argv[]) {
    int n, m;
    while (scanf("%d%d", &m, &n) != EOF) {
        scanf("%s", input_num);
        int length = strlen(input_num);
        num_a.set(0); // decimal_m
        num_b.set(1); // weight
        for (int i = length - 1; i >= 0; i--){
            int temp_num;
            if (input_num[i] >= '0' && input_num[i] <= '9')
                temp_num = input_num[i] - '0';
            else
                temp_num = input_num[i] - 'A' + 10;
            num_a = num_a + num_b * temp_num;
            num_b = num_b * m;
        }
        int size = 0;
        do {
            int temp_num = num_a % n;
            if (temp_num > 10)
                result[size++] = temp_num - 10 +'a';
            else
                result[size++] = temp_num + '0';
            num_a = num_a / n;
        } while (num_a.digit[0] != 0 || num_a.size != 1);
        for (int i = size - 1; i >= 0; i--)
            printf("%c", result[i]);
        printf("\n");
    }
    return 0;
}
